package com.zxcrm.web.controller.zxcrm;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zxcrm.common.annotation.Log;
import com.zxcrm.common.core.controller.BaseController;
import com.zxcrm.common.core.domain.AjaxResult;
import com.zxcrm.common.enums.BusinessType;
import com.zxcrm.zxcrm.domain.ZxcrmContact;
import com.zxcrm.zxcrm.service.IZxcrmContactService;
import com.zxcrm.common.utils.poi.ExcelUtil;
import com.zxcrm.common.core.page.TableDataInfo;

/**
 * 联系人Controller
 * 
 * @author xu
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/zxcrm/contact")
public class ZxcrmContactController extends BaseController
{
    @Autowired
    private IZxcrmContactService zxcrmContactService;

    /**
     * 查询联系人列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxcrmContact zxcrmContact)
    {
        startPage();
        List<ZxcrmContact> list = zxcrmContactService.selectZxcrmContactList(zxcrmContact);
        return getDataTable(list);
    }

    /**
     * 查询联系人列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(ZxcrmContact zxcrmContact)
    {
        List<ZxcrmContact> list = zxcrmContactService.selectZxcrmContactList(zxcrmContact);
        return AjaxResult.success(list);
    }


    /**
     * 导出联系人列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:export')")
    @Log(title = "联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxcrmContact zxcrmContact)
    {
        List<ZxcrmContact> list = zxcrmContactService.selectZxcrmContactList(zxcrmContact);
        ExcelUtil<ZxcrmContact> util = new ExcelUtil<ZxcrmContact>(ZxcrmContact.class);
        util.exportExcel(response, list, "联系人数据");
    }

    /**
     * 获取联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zxcrmContactService.selectZxcrmContactById(id));
    }

    /**
     * 获取联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:query')")
    @GetMapping(value = "/getContactListByCustomerId/{customerId}")
    public AjaxResult getContactListByCustomerId(@PathVariable("customerId") Long customerId)
    {
        return success(zxcrmContactService.selectContactListByCustomerId(customerId));
    }

    /**
     * 新增联系人
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:add')")
    @Log(title = "联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxcrmContact zxcrmContact)
    {
        return toAjax(zxcrmContactService.insertZxcrmContact(zxcrmContact));
    }

    /**
     * 修改联系人
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:edit')")
    @Log(title = "联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxcrmContact zxcrmContact)
    {
        return toAjax(zxcrmContactService.updateZxcrmContact(zxcrmContact));
    }

    /**
     * 删除联系人
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:contact:remove')")
    @Log(title = "联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zxcrmContactService.deleteZxcrmContactByIds(ids));
    }
}
